package com.zs.propertymanage.config;

import com.zs.propertymanage.inteceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 问题记录：
     * 1. 手动new的拦截器不归spring管，@Value注入不进去值
     * registry.addInterceptor(new JwtInterceptor()).addPathPatterns("/*").excludePathPatterns("/login");
     * 2. 解决办法是对拦截器自动装配，使用自动装配的拦截器
     * /@Autowired private JwtInterceptor jwtInterceptor;
     * registry.addInterceptor(jwtInterceptor).addPathPatterns("/*").excludePathPatterns("/login");
     */
    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .excludePathPatterns("/user/login", "/user/register", "/user/logout/**")
                .addPathPatterns("/**");
    }
}

